package com.fivestar.pmanager.dao.mapper;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import com.fivestar.pmanager.core.mapper.DBActionMapper;
import com.fivestar.pmanager.core.mapper.PaginatingMapper;
import com.fivestar.pmanager.model.SysModuleBean;

/**
 * 模块
 * SysModuleMapper
 * @author 
 *
 */
@Repository("sysModuleMapper")
public interface SysModuleMapper extends DBActionMapper<SysModuleBean>,
        PaginatingMapper<SysModuleBean>
{

    /**
     * 获取用户模块
     * @param userId 用户id
     * @return List<SmModuleBean>
     */
    @Results({
            @Result(property = "rowId", column = "row_id"),
            @Result(property = "moduleName", column = "module_name"),
            @Result(property = "moduleCode", column = "module_code"),
            @Result(property = "moduleUrl", column = "module_url"),
            @Result(property = "parentId", column = "parent_id")
    })
    @Select("select DISTINCT sm.row_id,sm.module_name,sm.module_code,sm.module_url,sm.parent_id " +
            "from sys_role_user sru " +
            "inner join sys_role_module srm on srm.role_id = sru.role_id " +
            "inner join sys_module sm on sm.row_id = srm.module_id " +
            "where sru.user_id = #{userId} " +
            "order by module_code ")
    List<SysModuleBean> getUserModule(@Param("userId")int userId);
    
    /**
     * 根据父id查询子菜单列表
     * @param pid
     * @return
     */
    @Results({
        @Result(property = "rowId", column = "row_id"),
        @Result(property = "moduleName", column = "module_name"),
        @Result(property = "moduleCode", column = "module_code"),
        @Result(property = "moduleUrl", column = "module_url"),
        @Result(property = "parentId", column = "parent_id"),
        @Result(property = "moduleType", column = "module_type"),
    })
    @Select("select a.row_id,a.module_name,a.module_code,a.parent_id,a.module_url,a.module_type from sys_module a " +
    		"where a.parent_id = #{parentId}  and a.is_deleted = 0 order by a.module_code asc")
    List<SysModuleBean> queryModuleByPid(@Param("parentId") String pid);

    /**
     * 查询角色的 模块列表
     * @param roleId
     * @return
     */
	List<SysModuleBean> queryRoleModuleByRoleId(Map<String,Object> map);
}
